package com.fir.my.batis.plus.until;

public class StringUtilss {
    public static byte[] byteMerger(byte[] bt1, byte[] bt2){
        byte[] bt3 = new byte[bt1.length+bt2.length];
        System.arraycopy(bt1, 0, bt3, 0, bt1.length);
        System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length);
        return bt3;
    }
    public static byte[] hexToByteArray4(String hexString) {
        System.out.println(hexString);
        System.out.println(hexString.length());
        if (hexString == null || hexString.length() % 4 != 0) {
            throw new IllegalArgumentException("Invalid hex string");
        }

        int length = hexString.length() / 4;
        byte[] byteArray = new byte[length];

        for (int i = 0; i < length; i++) {
            int startIndex = i * 4;
            int endIndex = startIndex + 4;
            String byteString = hexString.substring(startIndex, endIndex);
            int j = Integer.parseInt(byteString, 16);
            byteArray[i] = (byte)j ;
        }
        return byteArray;
    }
    public static byte[] hexToByteArray(String hexString) {
        if (hexString == null || hexString.length() % 2 != 0) {
            throw new IllegalArgumentException("Invalid hex string");
        }

        int length = hexString.length() / 2;
        byte[] byteArray = new byte[length];

        for (int i = 0; i < length; i++) {
            int startIndex = i * 2;
            int endIndex = startIndex + 2;
            String byteString = hexString.substring(startIndex, endIndex);
            byteArray[i] = (byte) Integer.parseInt(byteString, 16);
        }
        return byteArray;
    }


    public static void main(String[] args) {
        int j = Integer.parseInt("0014", 16);

        System.out.println(j);
        System.out.println((byte) 00);
    }
}
